<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
cfc('core')->checklogin();
if($_RQ['op']=='main'){
	$return['list']=array();
	$return['credit_types']=credit_types();
	$return['params']['type']=$_RQ['type']?:1;
	$return['params']['status']=$_RQ['status']?:0;
	if($_RQ['order_id']){
		$return['params']['order_id']=$_RQ['order_id'];
	}else{
		//exi('请选择订单！','error');
	}
	$return['setting']=$this->setting;
	set_html('title','配送记录');
	exi($return);
}
if($_RQ['op']=='list'){	
	$params=array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']);
	$orderby='id desc';
	$type=intval($_RQ['type']);
	if($type){
		$params['sendtype']=$type;
		$return['params']['type']=$type;
	}
	
	if($_RQ['status']){
		if($_RQ['status']=='other'){
			$orderby='daytime asc';
			$status=0;
		}else{
			$status=intval($_RQ['status']);
		}
		$params['status']=$status;
		$return['params']['status']=$status;
	}
	if(!$_RQ['status']){
		$day=date('Y-m-d');
		$params['day']=$day;
		$orderby='daytime asc';
		$params['status']=0;
	}
	$order_id=intval($_RQ['order_id']);
	if($order_id){
		$params['order_id']=$order_id;
		$return['params']['order_id']=$order_id;
	}
	$credit_types=credit_types();
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_peimilk_sendlog',$params,array($pindex,$psize),$total,'','',$orderby);
	$work_weekarray=array('日','一','二','三','四','五','六');
	if($list){
		foreach($list as &$item){
			$peiset=$this->pdo_get('peiset',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$item['buymid'],'merchid'=>$item['merchid']));
			$item['times']=str_array($peiset['times']);
			$item['goods']=json_decode($item['goods'],true);
			foreach($item['goods'] as &$gv){
				$gv['unit']=pdo_getcolumn('jy_weishop_goods',array('id'=>$gv['goodsid'],'uniacid'=>$_SESSION['uniacid']),'unit');
			}
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['is_addtitle']=$item['is_add']?'获得':'消费';
			if($item['sendtype']!=2){
				$item['statustitle']=$this->send_status[$item['status']];
			}else{
				$item['statustitle']=$this->send2_status[$item['status']];
			}
			$item['ordersn']=pdo_getcolumn('jy_weishop_order',array('id'=>$item['order_id']),'ordersn');
			$week = date('w', strtotime($item['day']));
			$item['week'] = '星期'.$work_weekarray[$week];
			$item['get_money']=$this->model('model')->get_peifee($item);
			//用户地址
			$item['order_out']=$this->model('model')->get_logaddress($item);
			if($item['mid']){
				$item['peimember']=pdo_get('jy_peimilk_member',array('mid'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),array('title','mobile','level_id'));
				$item['peimember']['level']=pdo_getcolumn('jy_peimilk_level',array('id'=>$item['peimember']['level_id'],'uniacid'=>$_SESSION['uniacid']),'title');
				$item['peimember']['level']=$item['peimember']['level']?:'普通等级';
			}
		}
	}
	$return['list']=$list;
	exi($return);
}
//报备
if($_RQ['op']=='baobei'){
	$post=get_postdata();
	$logid=intval($post['id']);
	if(!$logid){
		exi('订单不存在，请重新选择订单','error');
	}
	if($post['baobeitype']==3){
		$msg=$this->baobei_types3[$post['othertype']];
	}else{
		$msg=$this->baobei_types[$post['baobeitype']];
	}
	$sendlog=pdo_get('jy_peimilk_sendlog',array('id'=>$logid,'uniacid'=>$_SESSION['uniacid']));
	model('jy_peimilk/order')->add_baobei($sendlog,$msg,2);
	exi('报备成功！','','jy_peimilk/worker_order/list/');
}
//发起定期配送
if($_RQ['op']=='dingpei1'){
	$logid=intval($_RQ['id']);
	if(!$logid){
		exi('订单不存在，请重新选择订单','error');
	}
	$this->model('order')->sendlog1($logid,$day);
	exi('发起配送成功！');
}
//发起定期配送
if($_RQ['op']=='dingpei2'){
	$logid=intval($_RQ['id']);
	if(!$logid){
		exi('订单不存在，请重新选择订单','error');
	}
	$this->model('order')->sendlog2($logid);
	exi('确认收货完成！');
}